﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Expression.Interactivity.Layout;
using System.Windows.Interactivity;

namespace Eniux.Web.Framework.core
{
    public  class BaseWindow : ContentControl
    {
        public MouseDragElementBehavior DragBehavior{get;set;}

        public BaseWindow()
        {
            this.DefaultStyleKey = typeof(BaseWindow);
            this.Loaded += new RoutedEventHandler(BaseWindow_Loaded);

        }

        void BaseWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //添加拖动行为
            DragBehavior = new MouseDragElementBehavior();

            Interaction.GetBehaviors(this).Add(DragBehavior);
        }

        #region 字段
        //
        // 摘要:
        //     获取窗口在最小化或最大化之前的大小和位置。
        //
        // 返回结果:
        //     一个 System.Windows.Rect，指定窗口在最小化或最大化之前的大小和位置。
        public Rect RestoreBounds { get; private set; }
        #endregion

        #region 注册依赖属性

        #region   Top
        //
        // 摘要:
        //     获取或设置窗口上边缘相对于桌面的位置。
        //
        // 返回结果:
        //     以逻辑单位（1/96 英寸）表示的窗口上边缘位置。
        public double Top
        {
            get { return (double)DragBehavior.GetValue(MouseDragElementBehavior.YProperty); }
            set {  SetValue(TopProperty, value); }
        }
        private static readonly DependencyProperty TopProperty = DependencyProperty.Register(
            "Top", typeof(double), typeof(BaseWindow), new PropertyMetadata(0.0,OnTopPropertyChanged));
        private static void OnTopPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BaseWindow wnd=d as BaseWindow;
            if(wnd!=null)
            {

                wnd.DragBehavior.Y = (double)e.NewValue;
            }
        }
        #endregion

        #region Left
        //
        // 摘要:
        //     获取或设置窗口左边缘相对于桌面的位置。
        //
        // 返回结果:
        //     以逻辑单位（1/96 英寸）表示的窗口左边缘位置。
        public double Left
        {
            get { return (double)DragBehavior.GetValue(MouseDragElementBehavior.XProperty); }
            set { SetValue(LeftProperty, value); }
        }
        private static readonly DependencyProperty LeftProperty = DependencyProperty.Register(
            "Left", typeof(double), typeof(BaseWindow), new PropertyMetadata(0.0,OnLeftPropertyChanged));
        private static void OnLeftPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
        {
            BaseWindow wnd=d as BaseWindow;
            if(wnd!=null)
            {
                wnd.DragBehavior.X = (double)e.NewValue;
            }
        }
        #endregion

        #region Owner
        //
        // 摘要:
        //     获取或设置拥有此 Eniux.Web.Framework.core.BaseWindow 的 Eniux.Web.Framework.core.BaseWindow。
        //
        // 返回结果:
        //     一个 Eniux.Web.Framework.core.BaseWindow 对象，表示此 Eniux.Web.Framework.core.BaseWindow 的所有者。
        public BaseWindow Owner
        {
            get { return (BaseWindow)GetValue(OwnerProperty); }
            set { SetValue(OwnerProperty, value); }
        }
        private static readonly DependencyProperty OwnerProperty = DependencyProperty.Register(
            "Owner", typeof(BaseWindow), typeof(BaseWindow), new PropertyMetadata(null, OnOwnerPropertyChanged));
        private static void OnOwnerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BaseWindow wnd = d as BaseWindow;
            if (wnd != null)
            {

            }
        }
        #endregion

        #region ResizeMode
        //
        // 摘要:
        //     获取或设置大小调整模式。
        //
        // 返回结果:
        //     一个 Eniux.Web.Framework.core.ResizeMode 值，指定大小调整模式。
        public ResizeMode ResizeMode
        {
            get { return (ResizeMode)GetValue(ResizeModeProperty); }
            set { SetValue(ResizeModeProperty, value); }
        }
        private static readonly DependencyProperty ResizeModeProperty = DependencyProperty.Register(
            "ResizeMode", typeof(ResizeMode), typeof(BaseWindow), new PropertyMetadata(ResizeMode.CanResize, OnResizeModePropertyChanged));
        private static void OnResizeModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BaseWindow wnd = d as BaseWindow;
            if (wnd != null)
            {

            }
        }
        #endregion

        #region WindowStartupLocation
        //
        // 摘要:
        //     获取或设置窗口首次显示时的位置。
        //
        // 返回结果:
        //     一个 Eniux.Web.Framework.core.WindowStartupLocation 值，指定窗口首次显示时的顶边/左边位置。默认值为 Eniux.Web.Framework.core.WindowStartupLocation.Manual。
        public WindowStartupLocation WindowStartupLocation
        {
            get { return (WindowStartupLocation)GetValue(WindowStartupLocationProperty); }
            set { SetValue(WindowStartupLocationProperty, value); }
        }
        private static readonly DependencyProperty WindowStartupLocationProperty = DependencyProperty.Register(
            "WindowStartupLocation", typeof(WindowStartupLocation), typeof(BaseWindow), new PropertyMetadata(WindowStartupLocation.Manual, OnWindowStartupLocationPropertyChanged));
        private static void OnWindowStartupLocationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BaseWindow wnd = d as BaseWindow;
            if (wnd != null)
            {
               
            }
        }
        #endregion

        #region WindowState
        //
        // 摘要:
        //     获取或设置一个值，该值指示窗口是处于还原、最小化、最大化还是全屏状态。
        //
        // 返回结果:
        //     一个 Eniux.Web.Framework.core.WindowState，确定窗口是处于还原、最小化还是最大化状态。默认值为 Eniux.Web.Framework.core.WindowState.Normal（还原）。
        public WindowState WindowState
        {
            get { return (WindowState)GetValue(WindowStateProperty); }
            set { SetValue(WindowStateProperty, value); }
        }
        private static readonly DependencyProperty WindowStateProperty = DependencyProperty.Register(
            "WindowState", typeof(WindowState), typeof(BaseWindow), new PropertyMetadata(WindowState.Normal, OnWindowStatePropertyChanged));
        private static void OnWindowStatePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BaseWindow wnd = d as BaseWindow;
            if (wnd != null)
            {

            }
        }
        #endregion

        #region Topmost
        //
        // 摘要:
        //     获取或设置一个值，该值指示窗口是否出现在 Z 顺序的最顶层。
        //
        // 返回结果:
        //     如果窗口是最顶层元素，则为 true；否则为 false。
        public bool Topmost
        {
            get { return (bool)GetValue(TopmostProperty); }
            set { SetValue(TopmostProperty, value); }
        }
        private static readonly DependencyProperty TopmostProperty = DependencyProperty.Register(
            "Topmost", typeof(bool), typeof(BaseWindow), new PropertyMetadata(true, OnTopmostPropertyChanged));
        private static void OnTopmostPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BaseWindow wnd = d as BaseWindow;
            if (wnd != null)
            {

            }
        }

        #endregion

        #region Title
        //
        // 摘要:
        //     获取或设置窗口的标题。
        //
        // 返回结果:
        //     一个 System.String，包含窗口的标题。
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }
        private static readonly DependencyProperty TitleProperty = DependencyProperty.Register(
            "Title", typeof(string), typeof(BaseWindow), new PropertyMetadata(null));
        #endregion

        #region Icon
        //
        // 摘要:
        //     获取或设置窗口的图标。
        //
        // 返回结果:
        //     一个表示图标的 System.Windows.Media.ImageSource 对象。
        public ImageSource Icon
        {
            get { return (ImageSource)GetValue(IconProperty); }
            set { SetValue(IconProperty, value); }
        }
        private static readonly DependencyProperty IconProperty = DependencyProperty.Register(
            "Icon", typeof(ImageSource), typeof(BaseWindow), new PropertyMetadata(null));
        #endregion
        #endregion

        #region 方法

        /// <summary>
        /// 以非模态（modeless）窗口方式打开
        /// </summary>
        public  void Show()
        {
        }

        /// <summary>
        /// 以模态(modal)窗口方式打开
        /// </summary>
        public  void ShowDialog()
        {
        }

	    #endregion 

        #region 重写方法
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

        }
        #endregion
    }


}
